<template>
  <div class="blog-homepage" :class="theme">
    <el-container style="height: 100vh;">
      <el-aside width="200px" class="aside">
        <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#fff"
            text-color="#000"
            active-text-color="#409EFF"
        >
          <el-menu-item class="el-selection" index="1" @click="goToHome">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-submenu index="2">
            <template #title class="el-submenu-title">
              <i class="el-icon-document"></i>
              <span>功能菜单</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="2-1" @click="goToUserManage">用户管理</el-menu-item>
              <el-menu-item index="2-2" @click="goToArticleManage">文章管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template #title class="el-submenu-title">
              <i class="el-icon-setting"></i>
              <span>主题切换</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="3-1" @click="setThemeAction('blue')">蓝色风格</el-menu-item>
              <el-menu-item index="3-2" @click="setThemeAction('light-green')">浅绿色风格</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item class="el-selection" index="4">
            <i class="el-icon-setting"></i>
            <span slot="title">暂无功能组件1</span>
          </el-menu-item>
          <el-menu-item class="el-selection" index="5">
            <i class="el-icon-setting"></i>
            <span slot="title">暂无功能组件2</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
          <div class="header-right">
            <el-button class="return-login" type="text" @click="goToLogin">返回登陆</el-button>
          </div>
        </el-header>
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex';

export default {
  computed: {
    ...mapGetters(['theme']) // 使用 mapGetters 获取 theme
  },
  methods: {
    ...mapActions(['setTheme']), // 使用 mapActions 映射 setTheme action
    goToHome() {
      if (this.$route.name !== 'BlogHome') {
        this.$router.push({ name: 'BlogHome' });
      }
    },
    goToUserManage() {
      if (this.$route.name !== 'BlogUserManage') {
        this.$router.push({ name: 'BlogUserManage' });
      }
    },
    goToArticleManage() {
      if (this.$route.name !== 'BlogArticleManage') {
        this.$router.push({ name: 'BlogArticleManage' });
      }
    },
    goToLogin() {
      this.$router.push({ name: 'Login' });
    },
    setThemeAction(theme) {
      this.setTheme(theme); // 调用 action 设置主题
    }
  },
  mounted() {
  }
};
</script>

<style scoped lang="stylus">
.blog-homepage
  height 100%

  &.blue
    .header
      background-color #40c7ff
    .aside
      >>> .el-submenu__title
        background-color #40c7ff !important
      >>> .el-menu-item.is-active
        background-color #ecf5ff !important
      >>> .el-selection
        background-color #ecf5ff !important
    .main
      background-color #ecf5ff

  &.light-green
    .header
      background-color #8bc34a
    .aside
      >>> .el-submenu__title
        background-color #8bc34a !important
      >>> .el-menu-item.is-active
        background-color #c9fabe !important
      >>> .el-selection
        background-color #c2fab6 !important
    .main
      background-color #c2fab6

  .aside
    background-color #fff
    .el-menu
      border-right none

  .header
    color #fff
    text-align center
    line-height 60px
    display flex
    justify-content flex-end
    align-items center
    padding-right 20px
    .return-login
      color black
      margin-right 20px
    .header-right
      display flex
      align-items center

  .main
    color #333
    text-align center

@media (max-width: 800px)
  .blog-homepage
    .aside
      display none
</style>
